package id.laskarmedia.opnvpn_flutter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.VpnService;

public class ContextHelper {
    private static Activity mActivity;

    public static void setActivity(Activity activity) {
        mActivity = activity;
    }

    public static boolean startForResult(Intent intent, int requestCode) {
        if (mActivity != null && intent != null) {
            mActivity.startActivityForResult(intent, requestCode);
            return true;
        }
        return false;
    }

    public static Context getContext() {
        return mActivity;
    }

    public static Intent getVPNServiceIntent() {
        if (mActivity == null) {
            throw new IllegalStateException("Activity is not set in ContextHelper");
        }
        return VpnService.prepare(mActivity);
    }

    public static ConnectivityManager getConnectivityManager() {
        if (mActivity == null) {
            return null;
        }
        return (ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
    }
}